From b5af41171142f7c3e667e1965141fd155e734788 Mon Sep 17 00:00:00 2001 From: oliskoli Date: Wed, 29 Nov 2006 00:23:01 +0000 Subject: [PATCH] Fix calculation from and to INT32 Degrees (dec_to_intdeg/intdeg_to_dec). --- gpsbabel/csv_util.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/gpsbabel/csv_util.c b/gpsbabel/csv_util.c index e0817d44c..b92ebeb13 100644 --- a/gpsbabel/csv_util.c +++ b/gpsbabel/csv_util.c @@ -283,15 +283,14 @@ csv_lineparse(const char *stringstart, const char *delimited_by, #if CSVFMTS_ENABLED /*****************************************************************************/ /* dec_to_intdeg() - convert decimal degrees to integer degreees */ -/* usage: i = dec_to_intdeg(31.1234, 1); */ -/* i = dec_to_intdeg(91.1234, 0); */ +/* usage: i = dec_to_intdeg(31.1234); */ /*****************************************************************************/ static int -dec_to_intdeg(const double d, const int islat) +dec_to_intdeg(const double d) { int ideg = 0; - if (islat) { + if (d >= 0) { ideg = (2147483647) - (d * 8388608); } else { ideg = (2147483647) - (fabs(d) * 8388608) + 1; @@ -302,15 +301,14 @@ dec_to_intdeg(const double d, const int islat) /*****************************************************************************/ /* intdeg_to_dec() - convert integer degrees to decimal degreees */ -/* usage: lat = dec_to_intdeg(ilat, 1); */ -/* lon = dec_to_intdeg(ilon, 0); */ +/* usage: lat = dec_to_intdeg(ilat); */ /*****************************************************************************/ static double -intdeg_to_dec(const int ideg, const int islat) +intdeg_to_dec(const int ideg) { double d; - if (islat) { + if (ideg >= 0) { d = ((2147483647) - ideg) / (double)8388608; } else { d = ((-2147483647-1) + ideg) / (double)8388608; @@ -834,7 +832,7 @@ xcsv_parse_val(const char *s, waypoint *wpt, const field_map_t *fmp) } else if (strcmp(fmp->key, "LAT_INT32DEG") == 0) { /* latitude as a 32 bit integer offset */ - wpt->latitude = intdeg_to_dec((int) atof(s), 1); + wpt->latitude = intdeg_to_dec((int) atof(s)); } else if ( strcmp(fmp->key, "LAT_HUMAN_READABLE") == 0) { human_to_dec( s, &wpt->latitude, &wpt->longitude, 1 ); @@ -854,7 +852,7 @@ xcsv_parse_val(const char *s, waypoint *wpt, const field_map_t *fmp) } else if (strcmp(fmp->key, "LON_INT32DEG") == 0) { /* longitude as a 32 bit integer offset */ - wpt->longitude = intdeg_to_dec((int) atof(s), 0); + wpt->longitude = intdeg_to_dec((int) atof(s)); } else if ( strcmp(fmp->key, "LON_HUMAN_READABLE") == 0) { human_to_dec( s, &wpt->latitude, &wpt->longitude, 2 ); @@ -1245,7 +1243,7 @@ xcsv_waypt_pr(const waypoint *wpt) if (strcmp(fmp->key, "LAT_INT32DEG") == 0) { /* latitude as an integer offset from 0 degrees */ writebuff(buff, fmp->printfc, - dec_to_intdeg(lat, 1)); + dec_to_intdeg(lat)); } else if (strcmp(fmp->key, "LAT_HUMAN_READABLE") == 0) { dec_to_human( buff, fmp->printfc, "SN", lat ); @@ -1274,7 +1272,7 @@ xcsv_waypt_pr(const waypoint *wpt) if (strcmp(fmp->key, "LON_INT32DEG") == 0) { /* longitudee as an integer offset from 0 degrees */ writebuff(buff, fmp->printfc, - dec_to_intdeg(lon, 0)); + dec_to_intdeg(lon)); } else if (strcmp(fmp->key, "LON_HUMAN_READABLE") == 0) { dec_to_human( buff, fmp->printfc, "WE", lon ); -- 2.30.2